package it.struts.helloworld.services;

import it.struts.helloworld.model.Ordine;
import it.struts.helloworld.utils.HibernateUtils;

import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class OrdineService {
	


	

    public static void newOrdine(Ordine o)

            throws Exception {
    	
    	Session sess;

        try {

        	sess= HibernateUtils.getSessionFactory();

            Transaction tx = sess.beginTransaction();
            
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/YYYY");
            GregorianCalendar gc = new GregorianCalendar();
            String data = sdf.format(gc.getTime());
         
 
            o.setData(data);
            o.setStato("Ordinato");

            sess.save(o);
            tx.commit();


        } catch (Exception e) {
        	
        	e.printStackTrace();
        
        }

 

    }


}
